namespace QMVnSoft.Invoices
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.Controls.ChildGridControls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormCTKTLister : FormLister
    {
        private StatusColumn Column1;
        private StatusColumn Column2;
        private DataGridViewTextBoxColumn Column3;
        private DataGridViewTextBoxColumn Column4;
        private DataGridViewTextBoxColumn Column5;
        private DataGridViewTextBoxColumn Column6;
        private DataGridViewTextBoxColumn Column7;
        private NumericColumn Column8;
        private IContainer components;
        private GridControl grdDetail;
        private GridControl grdMaster;
        private SplitContainer GridContainer;
        private object id_Ngay_Ct1;
        private object id_Ngay_Ct2;
        private int ii_FilterByUser;
        private int ii_Locked;
        private int ii_Posted;
        private object ii_Tien1;
        private object ii_Tien2;
        private object is_Dien_Giai;
        private object is_Dien_GiaiC;
        private object is_Ghi_Chu;
        private object is_Ma_Bp;
        private object is_Ma_Dt;
        private object is_Ma_Hd;
        private object is_Ma_Km;
        private object is_Ma_Loai1;
        private object is_Ma_Loai2;
        private object is_Ma_Loai3;
        private object is_Ma_Sp;
        private object is_Ma_Tte;
        private object is_No_Co;
        private object is_So_Ct1;
        private object is_So_Ct2;
        private object is_Tk;
        private object is_Tk_Du;
        private DataTable oCanNotDelete;
        private DataGridViewTextBoxColumn Column9;
        private DataGridViewTextBoxColumn Column10;
        private DataGridViewTextBoxColumn Column11;
        private NumericColumn Column12;
        private NumericColumn Column13;
        private NumericColumn Column14;
        private DataGridViewTextBoxColumn Column15;
        private DataGridViewTextBoxColumn Column16;
        private DataGridViewTextBoxColumn Column17;
        private DataGridViewTextBoxColumn Column18;
        private DataGridViewTextBoxColumn Column19;
        private DataGridViewTextBoxColumn Column20;
        private DataGridViewTextBoxColumn Column21;
        private DataGridViewTextBoxColumn Column22;
        private CTKTDataAccess oMethod;

        public FormCTKTLister()
        {
            this.oMethod = new CTKTDataAccess();
            this.id_Ngay_Ct1 = DBNull.Value;
            this.id_Ngay_Ct2 = DBNull.Value;
            this.is_So_Ct1 = DBNull.Value;
            this.is_So_Ct2 = DBNull.Value;
            this.is_Ma_Tte = "*";
            this.is_Tk = DBNull.Value;
            this.is_No_Co = "*";
            this.is_Tk_Du = DBNull.Value;
            this.is_Ma_Dt = DBNull.Value;
            this.ii_Tien1 = DBNull.Value;
            this.ii_Tien2 = DBNull.Value;
            this.is_Ma_Km = DBNull.Value;
            this.is_Ma_Bp = DBNull.Value;
            this.is_Ma_Hd = DBNull.Value;
            this.is_Ma_Sp = DBNull.Value;
            this.is_Dien_Giai = DBNull.Value;
            this.is_Dien_GiaiC = DBNull.Value;
            this.is_Ghi_Chu = DBNull.Value;
            this.is_Ma_Loai1 = DBNull.Value;
            this.is_Ma_Loai2 = DBNull.Value;
            this.is_Ma_Loai3 = DBNull.Value;
            this.ii_FilterByUser = AppInstance.FilterByUser ? 1 : 0;
            this.InitializeComponent();
            base.MasterGridBrowser = this.grdMaster;
            base.DetailGridBrowser = this.grdDetail;
            (base.MasterGridBrowser.Columns[0] as StatusColumn).StatusField = 0;
            (base.MasterGridBrowser.Columns[1] as StatusColumn).StatusField = 1;
            base.DetailGridBrowser.CellEnter += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEnter);
            this.OnResetControls();
            base.ResizeForm();
        }

        public FormCTKTLister(string ps_InvoiceCode)
        {
            this.oMethod = new CTKTDataAccess();
            this.id_Ngay_Ct1 = DBNull.Value;
            this.id_Ngay_Ct2 = DBNull.Value;
            this.is_So_Ct1 = DBNull.Value;
            this.is_So_Ct2 = DBNull.Value;
            this.is_Ma_Tte = "*";
            this.is_Tk = DBNull.Value;
            this.is_No_Co = "*";
            this.is_Tk_Du = DBNull.Value;
            this.is_Ma_Dt = DBNull.Value;
            this.ii_Tien1 = DBNull.Value;
            this.ii_Tien2 = DBNull.Value;
            this.is_Ma_Km = DBNull.Value;
            this.is_Ma_Bp = DBNull.Value;
            this.is_Ma_Hd = DBNull.Value;
            this.is_Ma_Sp = DBNull.Value;
            this.is_Dien_Giai = DBNull.Value;
            this.is_Dien_GiaiC = DBNull.Value;
            this.is_Ghi_Chu = DBNull.Value;
            this.is_Ma_Loai1 = DBNull.Value;
            this.is_Ma_Loai2 = DBNull.Value;
            this.is_Ma_Loai3 = DBNull.Value;
            this.ii_FilterByUser = AppInstance.FilterByUser ? 1 : 0;
            this.InitializeComponent();
            base.InvoiceCode = ps_InvoiceCode;
            base.MasterGridBrowser = this.grdMaster;
            base.DetailGridBrowser = this.grdDetail;
            (base.MasterGridBrowser.Columns[0] as StatusColumn).StatusField = 0;
            (base.MasterGridBrowser.Columns[1] as StatusColumn).StatusField = 1;
            base.DetailGridBrowser.CellEnter += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEnter);
            this.OnResetControls();
            base.ResizeForm();
        }

        private void AddNotDeleteInvoice(object pd_Ngay_Ct, object ps_So_Ct, object ps_Dien_Giai)
        {
            if (this.oCanNotDelete == null)
            {
                this.oCanNotDelete = new DataTable();
                this.oCanNotDelete.Columns.Add("Ngay_Ct", typeof(DateTime));
                this.oCanNotDelete.Columns.Add("So_Ct", typeof(string));
                this.oCanNotDelete.Columns.Add("Dien_Giai", typeof(string));
            }
            DataRow row = this.oCanNotDelete.NewRow();
            row["Ngay_Ct"] = pd_Ngay_Ct;
            row["So_Ct"] = ps_So_Ct;
            row["Dien_Giai"] = ps_Dien_Giai;
            this.oCanNotDelete.Rows.Add(row);
        }

        private bool CheckInvoiceLock(object ps_InvoiceOrder, bool pb_Locked)
        {
            string str = null;
            if (!this.CheckInvoiceLock(ps_InvoiceOrder, pb_Locked, ref str))
            {
                MessageBox.Show(str, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            return true;
        }

        private bool CheckInvoiceLock(object ps_InvoiceOrder, bool pb_Locked, ref string ps_WarningMessage)
        {
            int num = this.oMethod.CheckInvoiceLock(AppInstance.Subsidiary, AppInstance.UserName, ps_InvoiceOrder);
            if (((num == 7) || ((num == 5) && pb_Locked)) || ((num == 2) && !pb_Locked))
            {
                ps_WarningMessage = base.AppInvoiceParameters.LockedMessage(num, pb_Locked);
                return false;
            }
            this.oMethod.Lock(AppInstance.UserName, ps_InvoiceOrder, pb_Locked);
            return true;
        }

        private bool CheckInvoicePost(object ps_InvoiceOrder, int pi_Posted)
        {
            string str = null;
            int num = 0;
            if (this.CheckInvoicePost(ps_InvoiceOrder, pi_Posted, ref str, ref num))
            {
                return true;
            }
            if (num == 8)
            {
                base.AppInvoiceParameters.ShowInvoiceUsed(ps_InvoiceOrder, str);
            }
            else
            {
                MessageBox.Show(str, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            return false;
        }

        private bool CheckInvoicePost(object ps_InvoiceOrder, int pi_Posted, ref string ps_WarningMessage, ref int pi_Result)
        {
            pi_Result = this.oMethod.CheckInvoicePost(AppInstance.Subsidiary, AppInstance.UserName, ps_InvoiceOrder, pi_Posted);
            if ((((((pi_Result == 9) || (pi_Result == 8)) || (pi_Result == 7)) || ((pi_Result == 6) && (pi_Posted == 1))) || ((pi_Result == 3) && (pi_Posted == 2))) || ((pi_Result == -1) && (pi_Posted == 0)))
            {
                ps_WarningMessage = base.AppInvoiceParameters.PostedMessageKT(pi_Result, pi_Posted);
                return false;
            }
            this.oMethod.Post(AppInstance.UserName, ps_InvoiceOrder, pi_Posted);
            return true;
        }

        private bool CheckInvoiceStatus(object ps_InvoiceOrder)
        {
            string str = null;
            int num = 0;
            if (this.CheckInvoiceStatus(ps_InvoiceOrder, ref str, ref num))
            {
                return true;
            }
            if (num == 8)
            {
                base.AppInvoiceParameters.ShowInvoiceUsed(ps_InvoiceOrder, str);
            }
            else
            {
                MessageBox.Show(str, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            return false;
        }

        private bool CheckInvoiceStatus(object ps_InvoiceOrder, ref string ps_WarningMessage, ref int pi_Result)
        {
            pi_Result = this.oMethod.CheckInvoiceStatus(AppInstance.Subsidiary, AppInstance.UserName, ps_InvoiceOrder);
            if (((pi_Result != 9) && (pi_Result != 8)) && (((pi_Result != 7) && (pi_Result != 6)) && (pi_Result != 5)))
            {
                return true;
            }
            ps_WarningMessage = base.AppInvoiceParameters.StatusMessage(pi_Result);
            return false;
        }

        private void DetailGridBrowser_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if ((base.DetailGridBrowser.CurrentRow != null) && (base.DetailGridBrowser.CurrentRow.DataBoundItem != null))
            {
                DataRow row = ((DataRowView) base.DetailGridBrowser.CurrentRow.DataBoundItem).Row;
                if (e.ColumnIndex == 1)
                {
                    string str = "";
                    base.AppInvoiceParameters.MakeAmountWarningMessage(true, base.LocalMasterRow["Posted"], base.MasterInvoiceOrder, row["Stt0"], base.LocalMasterRow["Ngay_Ct"], row["Tk"], DBNull.Value, base.LocalDetailTable, ref str);
                    base.WarningMessage = str;
                }
                else if (e.ColumnIndex == 8)
                {
                    string str2 = "";
                    base.AppInvoiceParameters.MakeAmountWarningMessage(true, base.LocalMasterRow["Posted"], base.MasterInvoiceOrder, row["Stt0"], base.LocalMasterRow["Ngay_Ct"], DBNull.Value, row["Ma_Dt"], base.LocalDetailTable, ref str2);
                    base.WarningMessage = str2;
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
            this.GridContainer = new System.Windows.Forms.SplitContainer();
            this.grdMaster = new QMVnSoft.Controls.GridControl();
            this.Column1 = new QMVnSoft.Controls.ChildGridControls.StatusColumn();
            this.Column2 = new QMVnSoft.Controls.ChildGridControls.StatusColumn();
            this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column8 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.grdDetail = new QMVnSoft.Controls.GridControl();
            this.Column9 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column10 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column11 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column12 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column13 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column14 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column15 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column16 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column17 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column18 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column19 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column20 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column21 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column22 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.GridContainer.Panel1.SuspendLayout();
            this.GridContainer.Panel2.SuspendLayout();
            this.GridContainer.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.grdMaster)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).BeginInit();
            this.SuspendLayout();
            // 
            // GridContainer
            // 
            this.GridContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.GridContainer.IsSplitterFixed = true;
            this.GridContainer.Location = new System.Drawing.Point(0, 24);
            this.GridContainer.Name = "GridContainer";
            this.GridContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
            // 
            // GridContainer.Panel1
            // 
            this.GridContainer.Panel1.Controls.Add(this.grdMaster);
            // 
            // GridContainer.Panel2
            // 
            this.GridContainer.Panel2.Controls.Add(this.grdDetail);
            this.GridContainer.Size = new System.Drawing.Size(794, 483);
            this.GridContainer.SplitterDistance = 226;
            this.GridContainer.SplitterWidth = 1;
            this.GridContainer.TabIndex = 2;
            // 
            // grdMaster
            // 
            this.grdMaster.AllowUserToAddRows = false;
            this.grdMaster.AllowUserToDeleteRows = false;
            this.grdMaster.CheckAutoSize = true;
            this.grdMaster.CheckColor = false;
            this.grdMaster.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdMaster.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column1,
            this.Column2,
            this.Column3,
            this.Column4,
            this.Column5,
            this.Column6,
            this.Column7,
            this.Column8});
            this.grdMaster.Dock = System.Windows.Forms.DockStyle.Fill;
            this.grdMaster.Font = new System.Drawing.Font("Arial", 8.25F);
            this.grdMaster.Location = new System.Drawing.Point(0, 0);
            this.grdMaster.Name = "grdMaster";
            this.grdMaster.ReadOnly = true;
            this.grdMaster.Size = new System.Drawing.Size(794, 226);
            this.grdMaster.TabIndex = 0;
            // 
            // Column1
            // 
            this.Column1.DataPropertyName = "Locked";
            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            this.Column1.DefaultCellStyle = dataGridViewCellStyle1;
            this.Column1.HeaderText = "";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            this.Column1.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column1.StatusField = 0;
            this.Column1.Width = 22;
            // 
            // Column2
            // 
            this.Column2.DataPropertyName = "Posted";
            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            this.Column2.DefaultCellStyle = dataGridViewCellStyle2;
            this.Column2.HeaderText = "";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column2.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column2.StatusField = 0;
            this.Column2.Width = 22;
            // 
            // Column3
            // 
            this.Column3.DataPropertyName = "Ngay_Ct";
            this.Column3.HeaderText = "Ngày";
            this.Column3.Name = "Column3";
            this.Column3.ReadOnly = true;
            this.Column3.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column3.Width = 62;
            // 
            // Column4
            // 
            this.Column4.DataPropertyName = "So_Ct";
            this.Column4.HeaderText = "Số";
            this.Column4.Name = "Column4";
            this.Column4.ReadOnly = true;
            this.Column4.Width = 70;
            // 
            // Column5
            // 
            this.Column5.DataPropertyName = "Dien_Giai";
            this.Column5.HeaderText = "Diễn giải (VN)";
            this.Column5.Name = "Column5";
            this.Column5.ReadOnly = true;
            this.Column5.Width = 172;
            // 
            // Column6
            // 
            this.Column6.DataPropertyName = "Desc_EN";
            this.Column6.HeaderText = "Diễn giải (EN)";
            this.Column6.Name = "Column6";
            this.Column6.ReadOnly = true;
            this.Column6.Width = 172;
            // 
            // Column7
            // 
            this.Column7.DataPropertyName = "Ten_Dt";
            this.Column7.HeaderText = "Đối tượng";
            this.Column7.Name = "Column7";
            this.Column7.ReadOnly = true;
            this.Column7.Width = 150;
            // 
            // Column8
            // 
            this.Column8.DataPropertyName = "TTien_NtN";
            dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column8.DefaultCellStyle = dataGridViewCellStyle3;
            this.Column8.HeaderText = "Tổng tiền";
            this.Column8.Name = "Column8";
            this.Column8.ReadOnly = true;
            this.Column8.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column8.UserTextNumericFormat = QMVnSoft.AppInstance.TextNumericFormat.ForeignAmount;
            this.Column8.Width = 81;
            // 
            // grdDetail
            // 
            this.grdDetail.AllowUserToAddRows = false;
            this.grdDetail.AllowUserToDeleteRows = false;
            this.grdDetail.CheckAutoSize = true;
            this.grdDetail.CheckColor = false;
            this.grdDetail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdDetail.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column9,
            this.Column10,
            this.Column11,
            this.Column12,
            this.Column13,
            this.Column14,
            this.Column15,
            this.Column16,
            this.Column17,
            this.Column18,
            this.Column19,
            this.Column20,
            this.Column21,
            this.Column22});
            this.grdDetail.Dock = System.Windows.Forms.DockStyle.Fill;
            this.grdDetail.Font = new System.Drawing.Font("Arial", 8.25F);
            this.grdDetail.Location = new System.Drawing.Point(0, 0);
            this.grdDetail.Name = "grdDetail";
            this.grdDetail.Size = new System.Drawing.Size(794, 256);
            this.grdDetail.TabIndex = 0;
            // 
            // Column9
            // 
            this.Column9.DataPropertyName = "No_Co";
            dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            this.Column9.DefaultCellStyle = dataGridViewCellStyle4;
            this.Column9.HeaderText = "Ps";
            this.Column9.Name = "Column9";
            this.Column9.ReadOnly = true;
            this.Column9.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column9.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column9.Width = 20;
            // 
            // Column10
            // 
            this.Column10.DataPropertyName = "Tk";
            this.Column10.HeaderText = "Tài khoản";
            this.Column10.MinimumWidth = 60;
            this.Column10.Name = "Column10";
            this.Column10.ReadOnly = true;
            this.Column10.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column10.Width = 60;
            // 
            // Column11
            // 
            this.Column11.DataPropertyName = "Ma_Tte";
            this.Column11.HeaderText = "Ttệ";
            this.Column11.MinimumWidth = 30;
            this.Column11.Name = "Column11";
            this.Column11.ReadOnly = true;
            this.Column11.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column11.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column11.Width = 30;
            // 
            // Column12
            // 
            this.Column12.DataPropertyName = "Tien_Nt";
            dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column12.DefaultCellStyle = dataGridViewCellStyle5;
            this.Column12.HeaderText = "Nguyên tệ";
            this.Column12.MinimumWidth = 100;
            this.Column12.Name = "Column12";
            this.Column12.ReadOnly = true;
            this.Column12.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column12.UserTextNumericFormat = QMVnSoft.AppInstance.TextNumericFormat.None;
            // 
            // Column13
            // 
            this.Column13.DataPropertyName = "Ty_Gia";
            dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column13.DefaultCellStyle = dataGridViewCellStyle6;
            this.Column13.HeaderText = "Tỷ giá";
            this.Column13.MinimumWidth = 60;
            this.Column13.Name = "Column13";
            this.Column13.ReadOnly = true;
            this.Column13.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column13.UserTextNumericFormat = QMVnSoft.AppInstance.TextNumericFormat.None;
            this.Column13.Width = 60;
            // 
            // Column14
            // 
            this.Column14.DataPropertyName = "Tien";
            dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column14.DefaultCellStyle = dataGridViewCellStyle7;
            this.Column14.HeaderText = "Thành tiền";
            this.Column14.MinimumWidth = 100;
            this.Column14.Name = "Column14";
            this.Column14.ReadOnly = true;
            this.Column14.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column14.UserTextNumericFormat = QMVnSoft.AppInstance.TextNumericFormat.None;
            // 
            // Column15
            // 
            this.Column15.DataPropertyName = "Ma_Bp";
            this.Column15.HeaderText = "Bộ phận";
            this.Column15.MinimumWidth = 70;
            this.Column15.Name = "Column15";
            this.Column15.ReadOnly = true;
            this.Column15.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.Column15.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column15.Width = 70;
            // 
            // Column16
            // 
            this.Column16.DataPropertyName = "Ma_Hd";
            this.Column16.HeaderText = "Hợp đồng";
            this.Column16.MinimumWidth = 70;
            this.Column16.Name = "Column16";
            this.Column16.ReadOnly = true;
            this.Column16.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.Column16.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column16.Width = 70;
            // 
            // Column17
            // 
            this.Column17.DataPropertyName = "Ma_Dt";
            this.Column17.HeaderText = "Đối tượng";
            this.Column17.MinimumWidth = 70;
            this.Column17.Name = "Column17";
            this.Column17.ReadOnly = true;
            this.Column17.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.Column17.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column17.Width = 70;
            // 
            // Column18
            // 
            this.Column18.DataPropertyName = "Han_Tt";
            this.Column18.HeaderText = "Hạn T.toán";
            this.Column18.MinimumWidth = 70;
            this.Column18.Name = "Column18";
            this.Column18.ReadOnly = true;
            this.Column18.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column18.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column18.Width = 70;
            // 
            // Column19
            // 
            this.Column19.DataPropertyName = "Ma_Km";
            this.Column19.HeaderText = "Khoản mục";
            this.Column19.MinimumWidth = 70;
            this.Column19.Name = "Column19";
            this.Column19.ReadOnly = true;
            this.Column19.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column19.Width = 70;
            // 
            // Column20
            // 
            this.Column20.DataPropertyName = "Ma_Sp";
            this.Column20.HeaderText = "Sản phẩm";
            this.Column20.MinimumWidth = 70;
            this.Column20.Name = "Column20";
            this.Column20.ReadOnly = true;
            this.Column20.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column20.Width = 70;
            // 
            // Column21
            // 
            this.Column21.DataPropertyName = "Dien_Giai";
            this.Column21.HeaderText = "Diễn giải (VN)";
            this.Column21.MinimumWidth = 120;
            this.Column21.Name = "Column21";
            this.Column21.ReadOnly = true;
            this.Column21.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column21.Width = 120;
            // 
            // Column22
            // 
            this.Column22.DataPropertyName = "Desc_EN";
            this.Column22.HeaderText = "Diễn giải (EN)";
            this.Column22.MinimumWidth = 120;
            this.Column22.Name = "Column22";
            this.Column22.ReadOnly = true;
            this.Column22.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column22.Width = 120;
            // 
            // FormCTKTLister
            // 
            this.ClientSize = new System.Drawing.Size(794, 532);
            this.Controls.Add(this.GridContainer);
            this.Name = "FormCTKTLister";
            this.StoredProcedure = "Danh_So_CtKT";
            this.Text = "Phiếu thu tiền mặt";
            this.Controls.SetChildIndex(this.GridContainer, 0);
            this.GridContainer.Panel1.ResumeLayout(false);
            this.GridContainer.Panel2.ResumeLayout(false);
            this.GridContainer.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.grdMaster)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        protected override void OnAdd()
        {
            base.LocalFormEditor = new FormCTKTEditor(base.AppInvoiceParameters);
            base.OnAdd();
        }

        protected override void OnCopy()
        {
            base.LocalFormEditor = new FormCTKTEditor(base.AppInvoiceParameters);
            base.OnCopy();
        }

        protected override void OnDelete()
        {
            if (MessageBox.Show(AppInstance.DeleMessage, AppInstance.SoftwareName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if ((base.MasterGridBrowser.SelectedRows != null) && (base.MasterGridBrowser.SelectedRows.Count <= 1))
                {
                    DataRow row = ((DataRowView) base.MasterGridBrowser.CurrentRow.DataBoundItem).Row;
                    if (!this.CheckInvoiceStatus(row["Stt"]))
                    {
                        return;
                    }
                    this.oMethod.Delete(AppInstance.UserName, row["Stt"]);
                    base.LocalMasterTable.Rows.Remove(row);
                }
                else
                {
                    this.oCanNotDelete = null;
                    string str = null;
                    int num = 0;
                    foreach (DataGridViewRow row2 in base.MasterGridBrowser.SelectedRows)
                    {
                        DataRow row3 = ((DataRowView) row2.DataBoundItem).Row;
                        if (this.CheckInvoiceStatus(row3["Stt"], ref str, ref num))
                        {
                            this.oMethod.Delete(AppInstance.UserName, row3["Stt"]);
                            base.LocalMasterTable.Rows.Remove(row3);
                        }
                        else
                        {
                            this.AddNotDeleteInvoice(row3["Ngay_Ct"], row3["So_Ct"], str);
                        }
                    }
                    if ((this.oCanNotDelete != null) && (this.oCanNotDelete.Rows.Count > 0))
                    {
                        new FormNotDeletes(base.AppInvoiceParameters.DeletedMessage(), this.oCanNotDelete).ShowDialog();
                    }
                }
                base.OnDelete();
            }
        }

        protected override void OnDetailVAT()
        {
            string str = "";
            object obj2 = "";
            object obj3 = "";
            decimal num = 0M;
            decimal num2 = 0M;
            decimal num3 = (decimal) base.LocalMasterRow["TTien_VAT1"];
            object obj4 = "";
            object obj5 = "";
            object obj6 = "";
            foreach (DataRow row in base.LocalDetailTable.Rows)
            {
                if ((row.RowState != DataRowState.Deleted) && (row["Tk_VAT"].ToString() == "C"))
                {
                    obj2 = row["Tk"];
                    str = row["No_Co"].ToString();
                    break;
                }
            }
            if (!string.IsNullOrEmpty(str.ToString()))
            {
                foreach (DataRow row2 in base.LocalDetailTable.Rows)
                {
                    if (row2.RowState != DataRowState.Deleted)
                    {
                        if ((row2["No_Co"].ToString() == str) && (row2["Tk_VAT"].ToString() != "C"))
                        {
                            num += (decimal) row2["Tien"];
                        }
                        if (((row2["No_Co"].ToString() != str) && (row2["Tk_VAT"].ToString() != "C")) && string.IsNullOrEmpty(obj3.ToString()))
                        {
                            obj3 = row2["Tk"];
                        }
                    }
                }
            }
            num2 = (decimal) base.LocalMasterRow["TTien_VAT0"];
            if (!string.IsNullOrEmpty(base.LocalMasterRow["Ma_Dt"].ToString()))
            {
                DataRow row3 = AppDataAccess.SelectDataRow(false, "DMDT", "Ma_Dt", base.LocalMasterRow["Ma_Dt"].ToString(), null);
                obj4 = base.LocalMasterRow["Ma_Dt"];
                if (row3 != null)
                {
                    obj5 = row3["Ms_Thue"];
                    obj6 = row3["Ten_Dt"];
                }
            }
            FormVATInput input = new FormVATInput(base.AppInvoiceParameters, base.MasterInvoiceOrder, (int) base.LocalMasterRow["Posted"], base.LocalMasterRow["Ngay_Ct"], base.LocalMasterRow["So_Ct"], base.LocalMasterRow["Ngay_Ct"], base.LocalMasterRow["So_Ct"], "", obj2, obj3, str, obj4, obj6, obj5, base.LocalMasterRow["Dien_Giai"], num, 0M, num2, num3, "K");
            input.VATToolbarButton = base.VATToolbarButton;
            input.Show();
            base.OnDetailVAT();
        }

        protected override void OnEdit()
        {
            base.LocalFormEditor = new FormCTKTEditor(base.AppInvoiceParameters);
            base.OnEdit();
        }

        protected override void OnFillData()
        {
            base.LocalMasterTable = this.oMethod.GetMasterTable(AppInstance.Subsidiary, AppInstance.DaysFilter, this.id_Ngay_Ct1, this.id_Ngay_Ct2, this.is_So_Ct1, this.is_So_Ct2, base.InvoiceCode, this.is_Ma_Tte, this.is_Tk, this.is_No_Co, this.is_Tk_Du, this.is_Ma_Dt, this.ii_Tien1, this.ii_Tien2, this.is_Ma_Km, this.is_Ma_Bp, this.is_Ma_Hd, this.is_Ma_Sp, this.is_Dien_Giai, this.is_Dien_GiaiC, this.is_Ma_Loai1, this.is_Ma_Loai2, this.is_Ma_Loai3, this.ii_FilterByUser, AppInstance.UserName, this.is_Ghi_Chu, this.ii_Posted, this.ii_Locked);
            base.OnFillData();
        }

        protected override void OnFilter()
        {
            FormCTKTFilter filter = new FormCTKTFilter();
            filter.Ngay_Ct1 = this.id_Ngay_Ct1;
            filter.Ngay_Ct2 = this.id_Ngay_Ct2;
            filter.So_Ct1 = this.is_So_Ct1;
            filter.So_Ct2 = this.is_So_Ct2;
            filter.Tk = this.is_Tk;
            filter.No_Co = this.is_No_Co;
            filter.Tk_Du = this.is_Tk_Du;
            filter.Tien1 = this.ii_Tien1;
            filter.Tien2 = this.ii_Tien2;
            filter.Ma_Tte = this.is_Ma_Tte;
            filter.Ma_Km = this.is_Ma_Km;
            filter.Ma_Bp = this.is_Ma_Bp;
            filter.Ma_Hd = this.is_Ma_Hd;
            filter.Ma_Dt = this.is_Ma_Dt;
            filter.Ma_Sp = this.is_Ma_Sp;
            filter.Dien_Giai = this.is_Dien_Giai;
            filter.Dien_GiaiC = this.is_Dien_GiaiC;
            filter.Ghi_Chu = this.is_Ghi_Chu;
            filter.Ma_Loai1 = this.is_Ma_Loai1;
            filter.Ma_Loai2 = this.is_Ma_Loai2;
            filter.Ma_Loai3 = this.is_Ma_Loai3;
            filter.FilterByUser = this.ii_FilterByUser;
            filter.Posted = this.ii_Posted;
            filter.Locked = this.ii_Locked;
            filter.ShowDialog();
            if (filter.CheckAccepted)
            {
                this.id_Ngay_Ct1 = filter.Ngay_Ct1;
                this.id_Ngay_Ct2 = filter.Ngay_Ct2;
                this.is_So_Ct1 = filter.So_Ct1;
                this.is_So_Ct2 = filter.So_Ct2;
                this.is_Tk = filter.Tk;
                this.is_No_Co = filter.No_Co;
                this.is_Tk_Du = filter.Tk_Du;
                this.ii_Tien1 = filter.Tien1;
                this.ii_Tien2 = filter.Tien2;
                this.is_Ma_Tte = filter.Ma_Tte;
                this.is_Ma_Km = filter.Ma_Km;
                this.is_Ma_Bp = filter.Ma_Bp;
                this.is_Ma_Hd = filter.Ma_Hd;
                this.is_Ma_Dt = filter.Ma_Dt;
                this.is_Ma_Sp = filter.Ma_Sp;
                this.is_Dien_Giai = filter.Dien_Giai;
                this.is_Dien_GiaiC = filter.Dien_GiaiC;
                this.is_Ghi_Chu = filter.Ghi_Chu;
                this.is_Ma_Loai1 = filter.Ma_Loai1;
                this.is_Ma_Loai2 = filter.Ma_Loai2;
                this.is_Ma_Loai3 = filter.Ma_Loai3;
                this.ii_FilterByUser = filter.FilterByUser;
                this.ii_Posted = filter.Posted;
                this.ii_Locked = filter.Locked;
                base.OnFilter();
            }
        }

        protected override void OnLock(bool pb_Locked)
        {
            if ((base.MasterGridBrowser.SelectedRows != null) && (base.MasterGridBrowser.SelectedRows.Count <= 1))
            {
                DataRow row = ((DataRowView) base.MasterGridBrowser.CurrentRow.DataBoundItem).Row;
                if (this.CheckInvoiceLock(row["Stt"], pb_Locked))
                {
                    row["Locked"] = pb_Locked;
                    base.LocalMasterRow["Locked"] = pb_Locked;
                }
            }
            else
            {
                this.oCanNotDelete = null;
                string str = null;
                foreach (DataGridViewRow row2 in base.MasterGridBrowser.SelectedRows)
                {
                    DataRow row3 = ((DataRowView) row2.DataBoundItem).Row;
                    if (this.CheckInvoiceLock(row3["Stt"], pb_Locked, ref str))
                    {
                        row3["Locked"] = pb_Locked;
                        if (base.LocalMasterRow["Stt"].Equals(row3["Stt"]))
                        {
                            base.LocalMasterRow["Locked"] = pb_Locked;
                        }
                    }
                    else
                    {
                        this.AddNotDeleteInvoice(row3["Ngay_Ct"], row3["So_Ct"], str);
                    }
                }
                if ((this.oCanNotDelete != null) && (this.oCanNotDelete.Rows.Count > 0))
                {
                    new FormNotDeletes(base.AppInvoiceParameters.LockedTitle(pb_Locked), this.oCanNotDelete).ShowDialog();
                }
            }
            base.OnLock(pb_Locked);
        }

        protected override void OnPost(int pi_Posted)
        {
            if ((base.MasterGridBrowser.SelectedRows != null) && (base.MasterGridBrowser.SelectedRows.Count <= 1))
            {
                DataRow row = ((DataRowView) base.MasterGridBrowser.CurrentRow.DataBoundItem).Row;
                if (this.CheckInvoicePost(row["Stt"], pi_Posted))
                {
                    row["Posted"] = pi_Posted;
                    base.LocalMasterRow["Posted"] = pi_Posted;
                }
            }
            else
            {
                this.oCanNotDelete = null;
                string str = null;
                int num = 0;
                foreach (DataGridViewRow row2 in base.MasterGridBrowser.SelectedRows)
                {
                    DataRow row3 = ((DataRowView) row2.DataBoundItem).Row;
                    if (this.CheckInvoicePost(row3["Stt"], pi_Posted, ref str, ref num))
                    {
                        row3["Posted"] = pi_Posted;
                        if (base.LocalMasterRow["Stt"].Equals(row3["Stt"]))
                        {
                            base.LocalMasterRow["Posted"] = pi_Posted;
                        }
                    }
                    else
                    {
                        this.AddNotDeleteInvoice(row3["Ngay_Ct"], row3["So_Ct"], str);
                    }
                }
                if ((this.oCanNotDelete != null) && (this.oCanNotDelete.Rows.Count > 0))
                {
                    new FormNotDeletes(base.AppInvoiceParameters.PostedTitle(pi_Posted), this.oCanNotDelete).ShowDialog();
                }
            }
            base.OnPost(pi_Posted);
        }

        internal override void OnResetControls()
        {
            if (!base.AppInvoiceParameters.BilingualUsed)
            {
                base.MasterGridBrowser.Columns[5].Visible = false;
                base.DetailGridBrowser.Columns[13].Visible = false;
            }
            if (!base.AppInvoiceParameters.AllowMultiCurrencies)
            {
                base.DetailGridBrowser.Columns[2].Visible = false;
                base.DetailGridBrowser.Columns[4].Visible = false;
            }
            if (base.AppInvoiceParameters.AllowDepartmentControl != 2)
            {
                base.DetailGridBrowser.Columns[6].Visible = false;
            }
            if (base.AppInvoiceParameters.AllowContractControl != 2)
            {
                base.DetailGridBrowser.Columns[7].Visible = false;
            }
            if (base.AppInvoiceParameters.AllowCategoryControl != 1)
            {
                base.DetailGridBrowser.Columns[10].Visible = false;
            }
            if (!base.AppInvoiceParameters.AllowProductControl)
            {
                base.DetailGridBrowser.Columns[11].Visible = false;
            }
            if (!base.AppInvoiceParameters.AllowPaymentTerm)
            {
                base.DetailGridBrowser.Columns[9].Visible = false;
            }
            base.OnResetControls();
        }

        internal override void OnShowMaster()
        {
            base.LocalMasterRow = this.oMethod.GetMasterDataRow(base.MasterInvoiceOrder);
            base.LocalDetailDataSet = this.oMethod.GetDetailDataSet(base.MasterInvoiceOrder);
            base.OnShowMaster();
        }

        internal override void OnShowMasterNotice()
        {
            string str = "";
            base.AppInvoiceParameters.MakeAmountWarningMessage(true, base.LocalMasterRow["Posted"], base.MasterInvoiceOrder, DBNull.Value, base.LocalMasterRow["Ngay_Ct"], DBNull.Value, base.LocalMasterRow["Ma_Dt"], base.LocalDetailTable, ref str);
            base.WarningMessage = str;
        }
    }
}

